using Microsoft.AspNetCore.Connections;
using Microsoft.Extensions.Options;
using System.Net;
using System.Text.Json.Serialization;

namespace Server
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder (args);

            
            builder.Services.ConfigureHttpJsonOptions(options =>
            {
                options.SerializerOptions.AddContext<AppJsonSerializerContext>();
            });
            builder.Services.AddFramework(new IPEndPoint(IPAddress.Loopback, 8009));
            
            builder.WebHost.UseKestrel(options =>
            {
                // TCP 8007
                options.ListenLocalhost(8007, builder =>
                {
                    builder.UseConnectionHandler<MyEchoConnectionHandler>();
                });

                // HTTP 5000
                options.ListenLocalhost(5000);

                // HTTPS 5001
                options.ListenLocalhost(5001, builder =>
                {
                    builder.UseHttps();
                });

            });
            var app = builder.Build();
            
            app.MapGet("/", () => "Hello World!");

            app.Run();
        }
    }
    [JsonSerializable(typeof(string))]
    internal partial class AppJsonSerializerContext : JsonSerializerContext
    {

    }
}